package Game.sprites;

import graphics.Animation;

/**
    The Player.
*/
public class Player extends Creature {

    private static final float JUMP_ACCEL=.003f;
    private final float MAX_VELOCITY_Y=1f;
    private final float MAX_VELOCITY_X=0.6f;
    private static final float JUMP_SPEED = -.95f;

    private boolean onGround;

    public Player(Animation left, Animation right,
        Animation deadLeft, Animation deadRight)
    {
        super(left, right, deadLeft, deadRight);
    }


    public void collideHorizontal() {
        setVelocityX(0);
    }


    public void collideVertical() {
        // check if collided with ground
        if (getVelocityY() > 0) {
            onGround = true;
        }
        setVelocityY(0);
    }


    public void setY(float y) {
        // check if falling
        if (Math.round(y) > Math.round(getY())) {
            onGround = false;
        }
        super.setY(y);
    }
    
    public void setVelocityX(float x){
        if((x<0 && x<-MAX_VELOCITY_X)){
            x=-MAX_VELOCITY_X;
        }else if((x>0 && x>MAX_VELOCITY_X)){
            x=MAX_VELOCITY_X;
        }
        super.setVelocityX(x);
    }


    public void wakeUp() {
        // do nothing
    }


    /**
        Makes the player jump if the player is on the ground or
        if forceJump is true.
    */
    public void jump(boolean forceJump) {
        if (onGround || forceJump) {
            onGround = false;
            setVelocityY(JUMP_SPEED);
        }
    }

    public void jump(float chargeTime) {
        //System.out.println("Jumped");
        //System.out.println(chargeTime);
        setVelocityY(-((chargeTime)*JUMP_ACCEL));
        //System.out.println("Y Vel: "+getVelocityY());
        if(getVelocityY()<(-MAX_VELOCITY_Y))
            setVelocityY(-MAX_VELOCITY_Y);
        onGround = false;
        /*if(doubleJump){
            doubleJump=false;
        }else{
            doubleJump=true;
        }*/
    }


    public float getMaxSpeed() {
        return 0.5f;
    }

}
